#ifndef MODEL_HEADER_VIZMF_PROJECT
#define MODEL_HEADER_VIZMF_PROJECT
#include <map>
#include <utility>
#include "src/core/workspace/workspace.h"
class Controller;
#include "src/core/generic/translator.h"
#include "src/core/scene/visitorparameters.h"
#include "src/core/generic/parser.h"

#include <QDebug>

extern Translator translator;

class Model
{
public:
  typedef std::map<int, WorkSpace> WSV;   // shulga: why not just std::vector?
  typedef WSV::iterator WS_iterator;
  typedef WSV::const_iterator WS_const_iterator;
  typedef std::string string;

  Model();
  void setController(Controller* pcontr) { controller = pcontr; }
  int addWorkspace(const string& name = translator.stdString("New workspace"))
  {
    int size = workspaces.size();
    workspaces.insert(std::pair<int, WorkSpace>(size, WorkSpace(size, name)));  // shulga: this will always insert!
    return size;
  }
  void addMolecule(const Molecule& mol, const int wspId)
  {
    workspaces[wspId].addMolecule(mol);
  }
  const Lattice* addLattice(const Lattice& latt, const int wspId)
  {
    return workspaces[wspId].addLattice(latt);
  }
  void addField(const Field& field, const Lattice* l, const int wspId)
  {
    workspaces[wspId].addField(field);
    (workspaces[wspId].fieldsEnd()--)->setLattice(l);
  }

  const WorkSpace& workspace(const int wspId) const
  {
    return workspaces.at(wspId);
  }
  WorkSpace& workspace(const int wspId)
  {
    return workspaces[wspId];
  }
  void removeWorkspace(const int wspId)
  {
    workspaces.erase(wspId);
  }

  ItemWidget* scene(int wspId) { return workspaces[wspId].scene(); }
  void loadVizParameters(const string filename = "")
  {
    if (filename.empty())
    {
      extern std::istringstream _def_atom_parameters_xml_;
      Parser::parseAtomProperties(_def_atom_parameters_xml_, &vizParameters);
    } else {
      Parser::parseAtomProperties(filename, &vizParameters, controller);
    }
  }
  const VisitorParameters& visitorParameters() const { return vizParameters; }

private:
  WSV workspaces;
  Controller *controller;
  VisitorParameters vizParameters;
};

#endif // MODEL_HEADER_VIZMF_PROJECT
